﻿using System;
using System.IO;
using System.Threading;
using System.Collections.Generic;
using System.Windows.Forms;

namespace PLock {
	static class Program {
		[STAThread]
		static void Main() {
			Application.EnableVisualStyles();
			Application.SetCompatibleTextRenderingDefault(false);

			string exename = Path.GetFileNameWithoutExtension(Application.ExecutablePath).ToLower();
			if (exename.StartsWith("plockportable")) {
				Settings.Instance.Portable = true;
				if (exename == "plockportablesa")
					Settings.Instance.Standalone = true;
				else
					Settings.Instance.Standalone = false;
			}
			using (Mutex m = new Mutex(false, "PLock_Process")) {
				if (!m.WaitOne(0)) {
					if (Settings.Instance.Portable) return;
					MessageBox.Show("A P-Lock process is already running on this machine; kill the existing process and try again", "Error", MessageBoxButtons.OK);
					return;
				}
				try {
					Settings.Instance.Load();
				} catch (Exception e) {
					MessageBox.Show("Could not load settings: " + e.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
					return;
				}

				// XXX perl script

				Application.Run(new ConfigDlg());
			}
		}
	}
}
